﻿using INTEX.DataBase.Tools;
using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Linq;
using WPFExcelReport.Helpers;

namespace WPFExcelReport
{
    public partial class YCAAV25Data
    {
        #region======Consumption====================
        private void CWBBST(DataRow dwABPOS, decimal nqty)
        {
            DataSet SetWD = null;
            DataSet SetWB = null;
            DataRow dwData = INTEXDB.WDECK.NewRow();
            dwData["WDMANDANT"] = dwABPOS["ABPMANDANT"];
            dwData["WDTYP"] = "B";
            dwData["WDAUFKRS"] = dwABPOS["ABPAUFKRS"];
            dwData["WDAUFLFD"] = dwABPOS["ABPAUFLFD"];
            dwData["WDAUFPOS"] = dwABPOS["ABPAUFPOS"];
            SetWD = INTEXDBC.QueryWDECK(dwData, 15);
            DataTable tbWDECK = SetWD.Tables[0];
            foreach (DataRow dwWDECK in tbWDECK.Rows)
            {
                decimal qty = System.Convert.ToDecimal(dwABPOS["ABPSOLLMENGE7"].ToString());
                decimal aqty = System.Convert.ToDecimal(dwABPOS["ABPEALFM"].ToString());
                decimal fqty = System.Convert.ToDecimal(dwWDECK["WDBEDARF"].ToString());
                decimal fget = System.Convert.ToDecimal(dwWDECK["WDZUGET"].ToString());
                decimal fissue = System.Convert.ToDecimal(dwWDECK["WDVERBR"].ToString());
                decimal ratio = fqty / qty;
                decimal fused = System.Math.Ceiling(nqty * ratio * 100) / 100;
                decimal ftouse = fused;
                bool IsCheck = true;
                string WDANZSTK = dwWDECK["WDANZSTK"].ToString();
                if (WDANZSTK == "000")
                {
                    IsCheck = true;
                }
                else
                {
                    IsCheck = false;
                }
                if (processtype == "RP")
                {
                    dwData = INTEXDB.WBBEW.NewRow();
                    dwData["WBEWMANDANT"] = dwWDECK["WDMANDANT"];
                    dwData["WBEWAUFKRS"] = dwWDECK["WDAUFKRS"];
                    dwData["WBEWAUFLFD"] = dwWDECK["WDAUFLFD"];
                    dwData["WBEWAUFPOS"] = dwWDECK["WDAUFPOS"];
                    dwData["WBEWART"] = dwWDECK["WDART"];
                    dwData["WBEWFARBE"] = dwWDECK["WDFARBE"];
                    SetWB = INTEXDBC.QueryWBBEW(dwData, 4);
                    if (SetWB.Tables[0].Rows.Count > 0)
                    {
                        message += dwWDECK["WDART"].ToString().Trim() + "-" + dwWDECK["WDFARBE"].ToString().Trim() + "不能重复修复！";
                        EventDispatcher.Instance.RaiseStatus(message, StatusEventType.StopProgress);
                        continue;
                    }
                }
                dwData = INTEXDB.WBBST.NewRow();
                dwData["WBBMANDANT"] = dwWDECK["WDMANDANT"];
                dwData["WBBWAKZ"] = dwWDECK["WDWAKZ"];
                dwData["WBBART"] = dwWDECK["WDART"];
                dwData["WBBFARBE"] = dwWDECK["WDFARBE"];
                dwData["WBBLO"] = PRLO;
                dwData["WBBLB"] = PRLB;
                SetWB = INTEXDBC.QueryWBBST(dwData, 6);
                if (SetWB.Tables[0].Rows.Count == 0)
                {

                    if (IsCheck)
                    {
                        IsSuccess = false;
                        message += dwABPOS["ABPAUFKRS"].ToString() + "-" + dwABPOS["ABPAUFLFD"].ToString() + "-" + dwWDECK["WDART"].ToString().Trim() + "-" + dwWDECK["WDFARBE"].ToString().Trim() + "面料在仓库" + PRLO + "数量缺少" + ftouse;
                        INTEXBL.CheckEvents("A003030", dwABPOS, message, null);
                        throw new Exception(message);
                        return;
                        //throw new Exception(message);
                    }
                    else
                    {
                        return;
                    }
                }
                //先看总数量是否足够
                var qWB = from WB in SetWB.Tables["WBBST"].AsEnumerable()
                          group WB by new
                          {
                              KRS = WB["WBBLO"],
                          }
                              into g
                              select new
                              {
                                  LO = g.Key,
                                  WBLG = g.Sum(EKP => Convert.ToDecimal(EKP.Field<decimal>("WBBISTKLG"))),
                              };
                foreach (var WB in qWB)
                {
                    decimal diff = WB.WBLG - fused;
                    if (diff<0)
                    {
                        if (IsCheck)
                        {

                            IsSuccess = false;
                            message += dwABPOS["ABPAUFKRS"].ToString() + "-" + dwABPOS["ABPAUFLFD"].ToString() + "-" + "需求:" + ftouse + ",仓库" + PRLO + "数量" + WB.WBLG + "。不足。" + dwWDECK["WDART"].ToString().Trim() + "-" + dwWDECK["WDFARBE"].ToString().Trim() + "-在仓库";
                            INTEXBL.CheckEvents("A003040", dwABPOS, message, null);
                            fused = WB.WBLG;
                            //throw new Exception(message);
                        }
                        else
                        {
                            fused = WB.WBLG;
                        }
                    }
                }

                dwWDECK["WDZUGET"] = fget + fused * 100;
                dwWDECK["WDVERBR"] = fissue + fused * 100;
                dwABPOS["ABPZUGET"] = dwWDECK["WDZUGET"];
                //dwABPOS["ABPZUGKG"] = dwWDECK["WDZUGET"];
                dwABPOS["ABPZUGSTK"] = System.Convert.ToDouble(dwABPOS["ABPZUGSTK"].ToString()) + 1;
                dwABPOS["ABPZTLGKOMP"] = "J";
                dwABPOS["ABPSMGKZZU"] = "J";
                dwABPOS["ABPWBSTA"] = "60";
                
                DataTable tb = SetWB.Tables[0].Clone();
                tb.TableName = "WBBST_ITX";
                DataRow dwWB = tb.NewRow();
                decimal wblg = 0;
                decimal wbwght = 0;
                foreach (DataRow wb in SetWB.Tables[0].Rows)
                {
                    if (fused == 0)
                    {
                        break;
                    }
                    decimal stklg = System.Convert.ToDecimal(wb["WBBISTKLG"].ToString()) / 1000;
                    decimal stkwg = System.Convert.ToDecimal(wb["WBBIGEW"].ToString()) / 1000;
                    if (stklg == 0)
                        continue;
                    if (SetExt.Tables.Contains("WBBST_ITX"))
                    {
                        SetExt.Tables.Remove("WBBST_ITX");
                    }
                    tb.Clear();
                    dwWB = tb.NewRow();
                    dwWB.ItemArray = wb.ItemArray;
                    tb.Rows.Add(dwWB);
                    SetExt.Merge(tb);
                    if (stklg <= fused)
                    {
                        STKNR = wb["WBBSTKNR"].ToString();
                        //长度不够
                        wb["WBBISTKLG"] = 0;
                        wb["WBBIGEW"] = 0;

                        wb["WBBVERSANDKZ"] = "J";                        
                        wb["WBBAUFTYP"] = "V";                        
                        wb["WBBAUFKRS"]=dwABPOS["ABPAUFKRS"];
                        wb["WBBAUFLFD"] = dwABPOS["ABPAUFLFD"];
                        wb["WBBAUFPOS"] = dwABPOS["ABPAUFPOS"];
                        wb["WBBAENDBEN"] = UserID;
                        wb["WBBAENDDAT"] = date;
                        wb["WBBVERSDAT"] = date;
                        
                        decimal WBBAENDZL = System.Convert.ToDecimal(wb["WBBAENDZL"].ToString());
                        wb["WBBAENDZL"] = WBBAENDZL + 1;

                        fused = fused - stklg;
                        DataSet STemp = Convert2WBBEW61(wb);
                        foreach (DataRow rw in STemp.Tables[0].Rows)
                        {
                            rw["WBEWMTR"] = 1000 * stklg;
                            rw["WBEWGEW"] = 1000 * stkwg;
                            rw["WBEWBUCHUHR"] = WBEWBUCHUHR;
                        }
                        wblg += stklg;
                        wbwght += stkwg;
                        Set4ITX.Merge(STemp);
                        STemp = Convert2WBBEW36(wb);
                        foreach (DataRow rw in STemp.Tables[0].Rows)
                        {
                            rw["WBEWMTR"] = 1000 * stklg;
                            rw["WBEWGEW"] = 1000 * stkwg;
                            rw["WBEWBUCHUHR"] = WBEWBUCHUHR;
                        }
                        Set4ITX.Merge(STemp);
                    }
                    else
                    { 
                        //WDZUGET	WDVERBR
                        wblg += System.Math.Ceiling(fused);
                        wbwght += System.Math.Ceiling(stkwg * fused / stklg);
                        decimal WBBSSTKLG = System.Convert.ToDecimal(wb["WBBSSTKLG"].ToString()) / 1000;
                        wb["WBBSSTKLG"] = System.Math.Ceiling(1000 * (WBBSSTKLG - fused));
                        decimal WBBSGEW = System.Convert.ToDecimal(wb["WBBSGEW"].ToString()) / 1000;
                        wb["WBBSGEW"] = System.Math.Ceiling(1000 * WBBSGEW * (WBBSSTKLG - fused) / WBBSSTKLG);

                        wb["WBBISTKLG"] = System.Math.Ceiling(1000 * (stklg - fused));
                        wb["WBBIGEW"] = System.Math.Ceiling(1000 * stkwg * (stklg - fused) / stklg);
                        NEW_WBBST(wb, fused, fused * stkwg / stklg);//以当前的这个WB去扣减
                        fused = 0;
                    }
                    if (Set4ITX.Tables.Contains("FCHAR"))
                    {
                        var qFC = from DataRow dwFC in Set4ITX.Tables["FCHAR"].AsEnumerable()
                                  where dwFC["FCCHAR"].ToString() == FCCHAR
                                  select dwFC;
                        foreach (DataRow dwFCHAR in qFC)
                        {
                            dwFCHAR["FCSTKNR"] = STKNR;
                        }
                    }
                }
                if (Set4ITX.Tables.Contains("KSLEIST"))
                {
                    foreach (DataRow rx in Set4ITX.Tables["KSLEIST"].Rows)
                    {
                        rx["KSLMGMTR"] = ftouse * 1000;
                        //                    rx["KSLMGKG"] = wbwght * 100;
                        if (rx["KSLAGANG"].ToString().Trim() == "FIN")
                        {
                            rx["KSLSTKNR"] = FCCHAR;
                        }
                        rx["KSLFILLER"] = Helper.Right("000000000" + WBEWBELEG, 9) + year.ToString()
                            + "    1A                                    ";
                    }
                }
                decimal ABPZUGKG = System.Convert.ToDecimal(dwABPOS["ABPZUGKG"].ToString());
                dwABPOS["ABPZUGKG"] = ABPZUGKG + System.Math.Round(100 * wbwght);
                Set4ITX.Merge(SetWD);//注意此时应当提交这个布卷，或者判断是否已经在内存中
                Set4ITX.Merge(SetWB);
            }
        }
        private void NEW_WBBST(DataRow dwBigRoll, decimal stklg, decimal stkwg)
        {

            DataSet SResult = null;
            DataSet STemp = null;
            SResult = Convert2WBBST(dwBigRoll);
            STemp = Convert2WBBEW26(dwBigRoll, stklg, stkwg);//减少新布卷
            Set4ITX.Merge(STemp);
            foreach (DataRow dwWB in SResult.Tables[0].Rows)
            {
                dwWB["WBBSSTKLG"] = stklg * 1000;
                dwWB["WBBISTKLG"] = 0;
                dwWB["WBBIGEW"] = 0;
                dwWB["WBBSGEW"] = stkwg * 1000;
                /*double WBBTANZ = System.Convert.ToDouble(dwInput["WBBTANZ"].ToString());
                WBBTANZ++;
                dwInput["WBBTANZ"] = Right("00" + WBBTANZ, 2);*/
                double WBBZMT = System.Convert.ToDouble(dwBigRoll["WBBZMT"].ToString());
                WBBZMT++;
                dwBigRoll["WBBZMT"] = System.Math.Round(WBBZMT, 0);
                string WBBSTKNR = dwBigRoll["WBBSTKNR"].ToString();
                STKNR = WBBSTKNR.Trim() + "/" + Right("00" + WBBZMT, 2) + " ";
                STKNR=Left(STKNR+"                               ",12);
                dwWB["WBBSTKNR"] = STKNR;             
                dwWB["WBBPOS"] = CWBDAT(dwWB);
                CWGBST(dwWB);
                //WBBPOS
                // WBBSTKNR
                #region========WBBST_ITX=========
                DataTable tb = SResult.Tables[0].Clone();
                tb.TableName = "WBBST_ITX";
                if (SetExt.Tables.Contains("WBBST_ITX"))
                {
                    SetExt.Tables.Remove("WBBST_ITX");
                }
                DataRow dwData = tb.NewRow();
                dwData.ItemArray = dwWB.ItemArray;
                tb.Rows.Add(dwData);
                SetExt.Merge(tb);
                #endregion
                STemp = Convert2WBBEW27(dwWB, stklg, stkwg);//增加新布卷
                Set4ITX.Merge(STemp);
                STemp = Convert2WBBEW61(dwWB);
                Set4ITX.Merge(STemp);
                STemp = Convert2WBBEW36(dwWB);
                Set4ITX.Merge(STemp);
            }
            Set4ITX.Merge(SResult);
        }
        private void CFBST(DataRow dwABPOS, decimal nqty)
        {

            DataSet SetFD = null;
            DataSet SetFB = null;
            DataRow dwData = INTEXDB.FDECK.NewRow();
            dwData["FDMANDANT"] = dwABPOS["ABPMANDANT"];
            dwData["FDSA"] = "V";
            dwData["FDTYP"] = "B";
            dwData["FDAUFKRS"] = dwABPOS["ABPAUFKRS"];
            dwData["FDAUFLFD"] = dwABPOS["ABPAUFLFD"];
            dwData["FDAUFPOS"] = dwABPOS["ABPAUFPOS"];
            SetFD = INTEXDBC.QueryFDECK(dwData, 1);
            DataTable tbFDECK = SetFD.Tables[0];
            foreach (DataRow dwFDECK in tbFDECK.Rows)
            {
                #region== dwFDECK===========
                decimal qty = System.Convert.ToDecimal(dwABPOS["ABPSOLLMENGE7"].ToString());
                decimal aqty = System.Convert.ToDecimal(dwABPOS["ABPEALFM"].ToString());
                decimal fqty = System.Convert.ToDecimal(dwFDECK["FDMENGE"].ToString());
                decimal fissue = System.Convert.ToDecimal(dwFDECK["FDVERBR"].ToString());
                decimal ratio = fqty / qty;
                decimal fused = System.Math.Round(nqty * 100 * ratio, 0);
                decimal fleft = System.Math.Round(nqty * 100 * ratio, 0);
                bool IsCheck = true;
                string FDKOMMISS = dwFDECK["FDKOMMISS"].ToString();
                if (FDKOMMISS.Trim() == "0")
                {
                    IsCheck = true;
                }
                else
                {
                    IsCheck = false;
                }
                if (fused == 0)
                    continue;
                if (processtype == "RP")
                { 
                    dwData = INTEXDB.FBEW.NewRow();
                    dwData["FBWMANDANT"] = dwFDECK["FDMANDANT"];
                    dwData["FBWAUFKRS"] = dwFDECK["FDAUFKRS"];
                    dwData["FBWAUFLFD"] = dwFDECK["FDAUFLFD"];
                    dwData["FBWAUFPOS"] = dwFDECK["FDAUFPOS"];
                    dwData["FBWART"] = dwFDECK["FDART"];
                    dwData["FBWFARBE"] = dwFDECK["FDFARBE"];
                    dwData["FBWGROE"] = dwFDECK["FDGROE"];
                    SetFB = INTEXDBC.QueryFBEW(dwData, 2);
                    if (SetFB.Tables[0].Rows.Count > 0)
                    {
                        message += dwFDECK["FDART"].ToString().Trim() + "-" + dwFDECK["FDFARBE"].ToString().Trim()   + "不能重复修补";
                        EventDispatcher.Instance.RaiseStatus(message, StatusEventType.StopProgress);
                        continue;
                    }
                }
                dwData = SetExt.Tables["FBST"].NewRow();
                //	FBART	FBVAR	FBFARBE	FBGROE
                dwData["FBMANDANT"] = dwFDECK["FDMANDANT"];
                dwData["FBART"] = dwFDECK["FDART"];
                dwData["FBVAR"] = dwFDECK["FDVAR"];
                dwData["FBFARBE"] = dwFDECK["FDFARBE"];
                dwData["FBGROE"] = dwFDECK["FDGROE"];
                dwData["FBLO"] = PRLO;
                dwData["FBLB"] = PRLB;
                SetFB = INTEXDBC.QueryFBST(dwData, 4);
                DataTable tb = tbFDECK.Clone();
                tb.TableName = "FDECK_ITX";
                DataRow dwFD = tb.NewRow();
                dwFD.ItemArray = dwFDECK.ItemArray;
                tb.Rows.Add(dwFD);
                if (SetExt.Tables.Contains("FDECK_ITX"))
                {
                    SetExt.Tables.Remove("FDECK_ITX");
                }
                SetExt.Merge(tb);
                if (SetFB.Tables[0].Rows.Count == 0)
                {
                    if (IsCheck)
                    {
                        IsSuccess = false;
                        message = dwABPOS["ABPAUFKRS"].ToString() + "-" + dwABPOS["ABPAUFLFD"].ToString() + "-" + "需求" + fused + "-" + dwFDECK["FDART"].ToString().Trim() + "-" + dwFDECK["FDFARBE"].ToString().Trim() + "-" + dwFDECK["FDGROE"].ToString().Trim() + "在仓库" + PRLO + "不存在";
                        INTEXBL.CheckEvents("A003050", dwABPOS, message, null);
                        return;
                        //throw new Exception(message);
                    }
                    else
                    {
                        IsSuccess = true; ;
                        return;
                    }
                }
                var qFB = from FB in SetFB.Tables[0].AsEnumerable()
                          group FB by new
                          {
                              LO = FB["FBLO"],
                          }
                              into g
                              select new
                              {
                                  LO = g.Key,
                                  FBME = g.Sum(FBP => Convert.ToDecimal(FBP.Field<decimal>("FBME"))),
                              };
                foreach (var FB in qFB)
                {
                    if (FB.FBME < fused)
                    {
                        if (IsCheck)
                        {
                            IsSuccess = false;
                            message = dwABPOS["ABPAUFKRS"].ToString() + "-" + dwABPOS["ABPAUFLFD"].ToString() + "-" + "需求" + fused + "-" + "在仓库" + PRLO + "中数量" + FB.FBME + "不足。" + dwFDECK["FDART"].ToString().Trim() + "-" + dwFDECK["FDFARBE"].ToString().Trim() + "-" + dwFDECK["FDGROE"].ToString().Trim();
                            INTEXBL.CheckEvents("A003060", dwABPOS, message, null);
                            fused = FB.FBME;
                            //throw new Exception(message);
                        }
                        else
                        {
                            fused = FB.FBME;
                        }
                    }
                }
                dwFDECK["FDVERBR"] = System.Math.Round(fissue + fused);
                foreach (DataRow fb in SetFB.Tables[0].Rows)
                {
                    if (fleft == 0)
                        break;
                    decimal WHQTY = System.Convert.ToDecimal(fb["FBME"].ToString());
                    decimal FBAENDZL = System.Convert.ToDecimal(fb["FBAENDZL"].ToString());
                    fb["FBAENDZL"] = FBAENDZL + 1;
                    if (WHQTY < fleft)//本批次不足
                    {
                        fb["FBME"] = 0;
                        fleft = fleft - WHQTY;
                        CFGBST(fb, WHQTY);
                        CFBEW(fb, WHQTY);
                    }
                    else
                    {
                        fb["FBME"] = WHQTY - fleft;
                        CFGBST(fb, fleft);
                        CFBEW(fb, fleft);
                        fleft = 0;
                    }
                }
                #endregion
                if (SetFB != null)
                {
                    Set4ITX.Merge(SetFB);
                }
            }
            Set4ITX.Merge(SetFD);
        }

        private void CFGBST(DataRow dwInput, decimal nqty)
        {

            DataTable tb = dwInput.Table.Clone();
            tb.TableName = "FBST_ITX";
            DataRow dwFB = tb.NewRow();
            dwFB.ItemArray = dwInput.ItemArray;
            tb.Rows.Add(dwFB);
            if (SetExt.Tables.Contains("FBST_ITX"))
            {
                SetExt.Tables.Remove("FBST_ITX");
            }
            SetExt.Merge(tb);
            DataSet SResult = null;
            DataRow dwData = INTEXDB.FGBST.NewRow();
            //	FBART	FBVAR	FBFARBE	FBGROE

            dwData["FGMANDANT"] = dwInput["FBMANDANT"];
            dwData["FGART"] = dwInput["FBART"];
            dwData["FGVAR"] = dwInput["FBVAR"];
            dwData["FGFARBE"] = dwInput["FBFARBE"];
            dwData["FGGROE"] = dwInput["FBGROE"];
            dwData["FGMJJ"] = year;
            dwData["FGMM"] = month;
            dwData["FGLO"] = PRLO;
            SResult = INTEXDBC.QueryFGBST(dwData, 1);
            foreach (DataRow dwFGBST in SResult.Tables[0].Rows)
            {
                dwFGBST["FGDLABST"] = dwFGBST["FGBSTA"];
                decimal FGME36 = System.Convert.ToDecimal(dwFGBST["FGME36"].ToString());
                dwFGBST["FGME36"] = FGME36 + nqty;
                decimal FGBSTA = System.Convert.ToDecimal(dwFGBST["FGBSTA"].ToString());
                dwFGBST["FGBSTA"] = FGBSTA - nqty;
                decimal FGBSTME = System.Convert.ToDecimal(dwFGBST["FGBSTME"].ToString());
                dwFGBST["FGBSTME"] = FGBSTME - nqty;
                decimal FGMINBST = System.Convert.ToDecimal(dwFGBST["FGMINBST"].ToString());
                dwFGBST["FGMINBST"] = FGMINBST - nqty;
                dwFGBST["FGAENDBEN"] = UserID;
                dwFGBST["FGAENDDAT"] = date;
                decimal FGAENDZL = System.Convert.ToDecimal(dwFGBST["FGAENDZL"].ToString());
                dwFGBST["FGAENDZL"] = FGAENDZL + 1;
            }
            Set4ITX.Merge(SResult);

        }
        private void CFBEW(DataRow dwInput, decimal nqty)
        {

            DataSet SResult = null;
            SResult = Convert2FBEW36(dwInput);
            foreach (DataRow dwFBEW in SResult.Tables[0].Rows)
            {
                dwFBEW["FBWME"] = nqty;
                dwFBEW["FBWBELEG"] = WBEWBELEG;
                dwFBEW["FBWBUCHUHR"] = WBEWBUCHUHR;
                WLFDNR++;
                dwFBEW["FBWLFDNR"] = WLFDNR;
            }
            Set4ITX.Merge(SResult);

        }

        private string CWBDAT(DataRow dwInput)
        {
            string stknr = "";

            DataSet SResult = null;
            DataRow dwWBDAT = null;
            DataSet STemp = null;
            DataRow dwData = INTEXDB.WBDAT.NewRow();
            dwData["WBMANDANT"] = dwInput["WBBMANDANT"];
            dwData["WBRWKRS"] = dwInput["WBBRWKRS"];
            dwData["WBRWLFD"] = dwInput["WBBRWLFD"];
            SResult = INTEXDBC.QueryWBDAT(dwData, 1);
            foreach (DataRow row in SResult.Tables[0].Rows)
            {
                dwWBDAT = row;
                decimal POS = System.Convert.ToDecimal(row["WBLESTKNR"].ToString());
                POS++;
                stknr = Right("0000" + POS, 4);
                row["WBLESTKNR"] = stknr;
                decimal WBAENDZL = System.Convert.ToDecimal(row["WBAENDZL"].ToString());
                row["WBAENDZL"] = WBAENDZL + 1;
            }
            Set4ITX.Merge(SResult);

            return stknr;
        }
        private void CWGBST(DataRow dwInput)
        {

            DataSet SResult = null;
            DataRow dwWGBST = null;
            DataSet STemp = null;
            DataRow dwData = INTEXDB.WGBST.NewRow();
            dwData["WGMANDANT"] = dwInput["WBBMANDANT"];
            dwData["WGLO"] = dwInput["WBBLO"];
            dwData["WGMJJ"] = year;
            dwData["WGMM"] = month;
            dwData["WGWAKZ"] = dwInput["WBBWAKZ"];
            dwData["WGART"] = dwInput["WBBART"];
            dwData["WGVAR"] = dwInput["WBBVAR"];
            dwData["WGFARBE"] = dwInput["WBBFARBE"];
            decimal stklg = System.Convert.ToDecimal(dwInput["WBBSSTKLG"].ToString()) / 10;
            decimal stkwg = System.Convert.ToDecimal(dwInput["WBBSGEW"].ToString()) / 10;
            SResult = INTEXDBC.QueryWGBST(dwData, 3);
            foreach (DataRow row in SResult.Tables[0].Rows)
            {
                dwWGBST = row;
                decimal WGME36 = System.Convert.ToDecimal(row["WGME36"].ToString());
                row["WGME36"] = WGME36 + stklg;
                decimal WGME36KG = System.Convert.ToDecimal(row["WGME36KG"].ToString());
                row["WGME36KG"] = WGME36KG + stkwg;
                decimal WGBSTA = System.Convert.ToDecimal(row["WGBSTA"].ToString());
                row["WGBSTA"] = WGBSTA - stklg;
                decimal WGBSTAKG = System.Convert.ToDecimal(row["WGBSTAKG"].ToString());
                row["WGBSTAKG"] = WGBSTAKG - stkwg;
                decimal WGBSTME = System.Convert.ToDecimal(row["WGBSTME"].ToString());
                row["WGBSTME"] = WGBSTME - stklg;
                decimal WGBSTMEKG = System.Convert.ToDecimal(row["WGBSTMEKG"].ToString());
                row["WGBSTMEKG"] = WGBSTMEKG - stkwg;
                //decimal WGMINBST = System.Convert.ToDecimal(row["WGMINBST"].ToString());
                //row["WGMINBST"] = WGMINBST - stklg;
                //decimal WGMINBSTKG = System.Convert.ToDecimal(row["WGMINBSTKG"].ToString());
                //row["WGMINBSTKG"] = WGMINBSTKG - stklg;
            }
            Set4ITX.Merge(SResult);
        }
        #endregion
    }
}
